package com.gorkr.hot100.medium;

import org.junit.jupiter.api.Test;

/**
 * @author 张心宇 <zhangxinyu20@kuaishou.com>
 * Created on 2023-01-10
 */
public class M240SearchA2DMatrixIISolutionII {

    public boolean searchMatrix(int[][] matrix, int target) {
        int n = matrix[0].length;
        int m = matrix.length;

        int i = 0, j = n-1;

        while (j>=0 && i<=m-1) {
            if (matrix[i][j] > target) {
                j--;
            } else if (matrix[i][j] < target) {
                i++;
            } else {
                return true;
            }
        }
        return false;
    }

    @Test
    public void test(){
//                int[][] matrix = new int[][] {{1, 4, 7, 11, 15}, {2, 5, 8, 12, 19}, {3, 6, 9, 16, 22}, {10, 13, 14, 17, 24},
//                        {18, 21, 23, 26, 30}};
        int[][] matrix = new int[][] {{1}};
        System.out.println(searchMatrix(matrix, 5));
    }

}
